package org.miku.sec;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SecurityGuard {
	
	public static String DMB5(String msg) {
		return MD5(MD5(msg));
	}
	
	public static String MD5(String msg) {
		String Ret = null;
		if(msg != null && msg.length() > 0) {
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");
				md.update(msg.getBytes());
				byte[] bytes = md.digest();
				
				int temp = 0;
				StringBuffer sb = new StringBuffer();
				for(int i = 0; i < bytes.length; i++) {
					temp = i < 0 ? i + 255 : i;
					if(i < 16) sb.append(0);
					sb.append(Integer.toHexString(temp));
				}
				
				Ret = sb.toString();
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
		}
		return Ret;
	}

}
